﻿namespace SubhadraSolutions.Sharp.Utils.Collections.Generic
{
    using System;

    using SubhadraSolutions.Sharp.Utils.Validation;

    /// <summary>
    /// The PredicateBasedFilter class.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PredicateBasedFilter<T> : IFilter<T>
    {
        /// <summary>
        /// The predicate
        /// </summary>
        private readonly Predicate<T> predicate; 
        public PredicateBasedFilter(Predicate<T> predicate)
        {
            Guard.ArgumentNotNull(predicate, "predicate");
            this.predicate = predicate;
        }

        /// <summary>
        /// Shoulds the filter.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns></returns>
        public bool ShouldFilter(T obj)
        {
            return this.predicate(obj);
        }
    }
}
